package com.kun.framework.core.util;

import cn.hutool.core.util.StrUtil;
import com.kun.framework.core.AbstractApplication;

import java.io.InputStream;

/**
 * 内部资源加载器，外部无法访问
 *
 * @author gzc
 * @since 2024/9/22
 **/
class ResourcesLoader {
    private static final String BASE_PACKAGE = "/com/kun/framework/core/";

    /**
     * 加载resources资源
     *
     * @param name 资源相对路径
     * @return 资源输入流
     */
    static InputStream load(String name) {
        if (StrUtil.isBlank(name)) {
            return null;
        }
        String resourcePath = name.indexOf("/") == 0 ? name : BASE_PACKAGE + name;
        return AbstractApplication.class.getResourceAsStream(resourcePath);
    }
}
